<!DOCTYPE html>
<html lang=zh>
<head><meta name="generator" content="Hexo 3.9.0">
    <!-- so meta -->
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="HandheldFriendly" content="True">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <meta name="description" content="前言es 都出了 7 了，是时候抛弃那些老的写法，试试那些 es 的新属性，新语法。为了保证代码的兼容性，可以在写代码的时候使用 es 新语法，然后使用 babel 编译成兼容性代码。那么到底该怎么做呢？ 开始安装babel-cli 1234# 初始化项目npm init# 安装babelcnpm install babel-cli --save-dev 设定转码规则 1cnpm install">
<meta name="keywords" content="nodejs">
<meta property="og:type" content="article">
<meta property="og:title" content="如何使用babel编译nodejs程序">
<meta property="og:url" content="https://andyliwr.github.io/2017/12/05/nodejs_babel/index.html">
<meta property="og:site_name" content="月光倾城的代码小屋">
<meta property="og:description" content="前言es 都出了 7 了，是时候抛弃那些老的写法，试试那些 es 的新属性，新语法。为了保证代码的兼容性，可以在写代码的时候使用 es 新语法，然后使用 babel 编译成兼容性代码。那么到底该怎么做呢？ 开始安装babel-cli 1234# 初始化项目npm init# 安装babelcnpm install babel-cli --save-dev 设定转码规则 1cnpm install">
<meta property="og:locale" content="zh-CN">
<meta property="og:image" content="https://file.lantingshucheng.com/blog/node-v.png/default">
<meta property="og:updated_time" content="2020-01-15T06:30:09.120Z">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="如何使用babel编译nodejs程序">
<meta name="twitter:description" content="前言es 都出了 7 了，是时候抛弃那些老的写法，试试那些 es 的新属性，新语法。为了保证代码的兼容性，可以在写代码的时候使用 es 新语法，然后使用 babel 编译成兼容性代码。那么到底该怎么做呢？ 开始安装babel-cli 1234# 初始化项目npm init# 安装babelcnpm install babel-cli --save-dev 设定转码规则 1cnpm install">
<meta name="twitter:image" content="https://file.lantingshucheng.com/blog/node-v.png/default">
    
    
        
          
              <link rel="shortcut icon" href="/images/favicon.ico">
          
        
        
          
            <link rel="icon" type="image/png" href="/images/favicon-192x192.png" sizes="192x192">
          
        
        
          
            <link rel="apple-touch-icon" sizes="180x180" href="/images/apple-touch-icon.png">
          
        
    
    <!-- title -->
    <title>如何使用babel编译nodejs程序</title>
    <!-- styles -->
    <link rel="stylesheet" href="/css/style.css">
    <!-- persian styles -->
    
      <link rel="stylesheet" href="/css/rtl.css">
    
    <!-- rss -->
    
    
</head>

<body class="max-width mx-auto px3 ltr">
    
      <div id="header-post">
  <a id="menu-icon" href="#"><i class="fas fa-bars fa-lg"></i></a>
  <a id="menu-icon-tablet" href="#"><i class="fas fa-bars fa-lg"></i></a>
  <a id="top-icon-tablet" href="#" onclick="$('html, body').animate({ scrollTop: 0 }, 'fast');" style="display:none;"><i class="fas fa-chevron-up fa-lg"></i></a>
  <span id="menu">
    <span id="nav">
      <ul>
         
          <li><a href="/">首页</a></li>
         
          <li><a href="/archives/">归档</a></li>
         
          <li><a href="/search/">搜索</a></li>
         
          <li><a href="/tags/">标签</a></li>
         
          <li><a href="/others/">其他文章</a></li>
        
      </ul>
    </span>
    <br/>
    <span id="actions">
      <ul>
        
        <li><a class="icon" href="/2017/12/05/nodejs_spider_ip/"><i class="fas fa-chevron-left" aria-hidden="true" onmouseover="$('#i-prev').toggle();" onmouseout="$('#i-prev').toggle();"></i></a></li>
        
        
        <li><a class="icon" href="/2017/12/05/travis_nodejs_publish/"><i class="fas fa-chevron-right" aria-hidden="true" onmouseover="$('#i-next').toggle();" onmouseout="$('#i-next').toggle();"></i></a></li>
        
        <li><a class="icon" href="#" onclick="$('html, body').animate({ scrollTop: 0 }, 'fast');"><i class="fas fa-chevron-up" aria-hidden="true" onmouseover="$('#i-top').toggle();" onmouseout="$('#i-top').toggle();"></i></a></li>
        <li><a class="icon" href="#"><i class="fas fa-share-alt" aria-hidden="true" onmouseover="$('#i-share').toggle();" onmouseout="$('#i-share').toggle();" onclick="$('#share').toggle();return false;"></i></a></li>
      </ul>
      <span id="i-prev" class="info" style="display:none;">上一篇</span>
      <span id="i-next" class="info" style="display:none;">下一篇</span>
      <span id="i-top" class="info" style="display:none;">返回顶部</span>
      <span id="i-share" class="info" style="display:none;">分享文章</span>
    </span>
    <br/>
    <div id="share" style="display: none">
      <ul>
  <li><a class="icon" href="http://www.facebook.com/sharer.php?u=https://andyliwr.github.io/2017/12/05/nodejs_babel/"><i class="fab fa-facebook " aria-hidden="true"></i></a></li>
  <li><a class="icon" href="https://twitter.com/share?url=https://andyliwr.github.io/2017/12/05/nodejs_babel/&text=如何使用babel编译nodejs程序"><i class="fab fa-twitter " aria-hidden="true"></i></a></li>
  <li><a class="icon" href="http://www.linkedin.com/shareArticle?url=https://andyliwr.github.io/2017/12/05/nodejs_babel/&title=如何使用babel编译nodejs程序"><i class="fab fa-linkedin " aria-hidden="true"></i></a></li>
  <li><a class="icon" href="https://pinterest.com/pin/create/bookmarklet/?url=https://andyliwr.github.io/2017/12/05/nodejs_babel/&is_video=false&description=如何使用babel编译nodejs程序"><i class="fab fa-pinterest " aria-hidden="true"></i></a></li>
  <li><a class="icon" href="mailto:?subject=如何使用babel编译nodejs程序&body=Check out this article: https://andyliwr.github.io/2017/12/05/nodejs_babel/"><i class="fas fa-envelope " aria-hidden="true"></i></a></li>
  <li><a class="icon" href="https://getpocket.com/save?url=https://andyliwr.github.io/2017/12/05/nodejs_babel/&title=如何使用babel编译nodejs程序"><i class="fab fa-get-pocket " aria-hidden="true"></i></a></li>
  <li><a class="icon" href="http://reddit.com/submit?url=https://andyliwr.github.io/2017/12/05/nodejs_babel/&title=如何使用babel编译nodejs程序"><i class="fab fa-reddit " aria-hidden="true"></i></a></li>
  <li><a class="icon" href="http://www.stumbleupon.com/submit?url=https://andyliwr.github.io/2017/12/05/nodejs_babel/&title=如何使用babel编译nodejs程序"><i class="fab fa-stumbleupon " aria-hidden="true"></i></a></li>
  <li><a class="icon" href="http://digg.com/submit?url=https://andyliwr.github.io/2017/12/05/nodejs_babel/&title=如何使用babel编译nodejs程序"><i class="fab fa-digg " aria-hidden="true"></i></a></li>
  <li><a class="icon" href="http://www.tumblr.com/share/link?url=https://andyliwr.github.io/2017/12/05/nodejs_babel/&name=如何使用babel编译nodejs程序&description="><i class="fab fa-tumblr " aria-hidden="true"></i></a></li>
</ul>

    </div>
    <div id="toc">
      <ol class="toc"><li class="toc-item toc-level-4"><a class="toc-link" href="#前言"><span class="toc-number">1.</span> <span class="toc-text">前言</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#开始"><span class="toc-number">2.</span> <span class="toc-text">开始</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#使用nodemon监听文件变化"><span class="toc-number">3.</span> <span class="toc-text">使用nodemon监听文件变化</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#编译生产环境代码"><span class="toc-number">4.</span> <span class="toc-text">编译生产环境代码</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#将babel的配置写入到-babelrc文件中"><span class="toc-number">5.</span> <span class="toc-text">将babel的配置写入到.babelrc文件中</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#续篇"><span class="toc-number">6.</span> <span class="toc-text">续篇</span></a></li></ol>
    </div>
  </span>
</div>

    
    <div class="content index py4">
        
        <article class="post" itemscope itemtype="http://schema.org/BlogPosting">
  <header>
    
    <h1 class="posttitle" itemprop="name headline">
        如何使用babel编译nodejs程序
    </h1>



    <div class="meta">
      <span class="author" itemprop="author" itemscope itemtype="http://schema.org/Person">
        <span itemprop="name">月光倾城的代码小屋</span>
      </span>
      
    <div class="postdate">
        <time datetime="2017-12-05T15:04:31.000Z" itemprop="datePublished">2017-12-05</time>
    </div>


      

      
    <div class="article-tag">
        <i class="fas fa-tag"></i>
        <a class="tag-link" href="/tags/nodejs/">nodejs</a>
    </div>


    </div>
  </header>
  

  <div class="content" itemprop="articleBody">
    <h4 id="前言"><a href="#前言" class="headerlink" title="前言"></a>前言</h4><p>es 都出了 7 了，是时候抛弃那些老的写法，试试那些 es 的新属性，新语法。为了保证代码的兼容性，可以在写代码的时候使用 es 新语法，然后使用 babel 编译成兼容性代码。那么到底该怎么做呢？</p>
<h4 id="开始"><a href="#开始" class="headerlink" title="开始"></a>开始</h4><p>安装<code>babel-cli</code></p>
<figure class="highlight mipsasm"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment"># 初始化项目</span></span><br><span class="line">npm init</span><br><span class="line"><span class="comment"># 安装babel</span></span><br><span class="line">cnpm <span class="keyword">install </span><span class="keyword">babel-cli </span>--save-dev</span><br></pre></td></tr></table></figure>
<p>设定转码规则</p>
<figure class="highlight mipsasm"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">cnpm <span class="keyword">install </span>--save-dev <span class="keyword">babel-preset-es2015 </span><span class="keyword">babel-preset-stage-2</span></span><br></pre></td></tr></table></figure>
<p>常见的规则如下：</p>
<figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment"># ES2015转码规则</span></span><br><span class="line">$ npm <span class="keyword">install</span> <span class="comment">--save-dev babel-preset-es2015</span></span><br><span class="line"></span><br><span class="line"><span class="comment"># react转码规则</span></span><br><span class="line">$ npm <span class="keyword">install</span> <span class="comment">--save-dev babel-preset-react</span></span><br><span class="line"></span><br><span class="line"><span class="comment"># ES7不同阶段语法提案的转码规则（共有4个阶段），选装一个</span></span><br><span class="line">$ npm <span class="keyword">install</span> <span class="comment">--save-dev babel-preset-stage-0</span></span><br><span class="line">$ npm <span class="keyword">install</span> <span class="comment">--save-dev babel-preset-stage-1</span></span><br><span class="line">$ npm <span class="keyword">install</span> <span class="comment">--save-dev babel-preset-stage-2</span></span><br><span class="line">$ npm <span class="keyword">install</span> <span class="comment">--save-dev babel-preset-stage-3</span></span><br></pre></td></tr></table></figure>
<p>新建<code>app.js</code>，并输入一下内容</p>
<figure class="highlight coffeescript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">import</span> http <span class="keyword">from</span> <span class="string">'http'</span>;</span><br><span class="line"></span><br><span class="line">http.createServer(<span class="function"><span class="params">(req, res)</span> =&gt;</span> &#123;</span><br><span class="line">  res.writeHead(<span class="number">200</span>, &#123;<span class="string">'Content-Type'</span>: <span class="string">'text/plain'</span>&#125;);</span><br><span class="line">  res.end(<span class="string">'Hello World\n'</span>);</span><br><span class="line">&#125;).listen(<span class="number">1337</span>, <span class="string">'127.0.0.1'</span>);</span><br><span class="line"></span><br><span class="line"><span class="built_in">console</span>.log(<span class="string">'Server running at http://127.0.0.1:1337/'</span>);</span><br></pre></td></tr></table></figure>
<p>在<code>package.json</code>里添加如下命令：</p>
<figure class="highlight 1c"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"><span class="string">"scripts"</span>: &#123;</span><br><span class="line">  <span class="string">"start"</span>: <span class="string">"babel-node index.js --presets es2015,stage-2"</span></span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<p>这样就可以通过运行<code>npm run start</code>来启动<code>app.js</code>了</p>
<h4 id="使用nodemon监听文件变化"><a href="#使用nodemon监听文件变化" class="headerlink" title="使用nodemon监听文件变化"></a>使用<code>nodemon</code>监听文件变化</h4><p>将<code>nodemon</code>和<code>npm run start</code>结合起来使用，这样一旦文件发生变化，babel 就能自动编译改动的文件</p>
<figure class="highlight q"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">cnpm install --<span class="built_in">save</span>-<span class="built_in">dev</span> nodemon</span><br></pre></td></tr></table></figure>
<p>修改<code>start</code>命令为：</p>
<figure class="highlight 1c"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"><span class="string">"scripts"</span>: &#123;</span><br><span class="line">  <span class="string">"start"</span>: <span class="string">"nodemon index.js --exec babel-node --presets es2015,stage-2"</span></span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<p>重新使用<code>npm run start</code>启动<code>app.js</code>，然后修改<code>app.js</code>，在按下<code>ctrl+s</code>的时候后 babel 就会自动编译<code>app.js</code></p>
<h4 id="编译生产环境代码"><a href="#编译生产环境代码" class="headerlink" title="编译生产环境代码"></a>编译生产环境代码</h4><p>代码上生产环境的时候，我们需要将编译好的文件放在一个单独的目录下。新建目录，并将<code>app.js</code>移至该目录下：</p>
<figure class="highlight properties"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="attr">mkdir</span> <span class="string">src</span></span><br><span class="line"><span class="attr">mv</span> <span class="string">app.js src/</span></span><br></pre></td></tr></table></figure>
<p>对<code>package.json</code>做如下修改：</p>
<figure class="highlight 1c"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="string">"scripts"</span>: &#123;</span><br><span class="line">  <span class="string">"start"</span>: <span class="string">"nodemon src/index.js --exec babel-node --presets es2015,stage-2"</span>,</span><br><span class="line">  <span class="string">"build"</span>: <span class="string">"babel lib -d dist --presets es2015,stage-2"</span>,</span><br><span class="line">  <span class="string">"serve"</span>: <span class="string">"node dist/index.js"</span></span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<p>这样当你运行<code>npm run build</code>的时候，<code>babel</code>就会自动将改动文件编译并放至<code>dist</code>目录下，上生产的时候只需要复制<code>dist</code>目录下的代码就行了</p>
<p>对于 git 项目，可能你不需要每次都提交<code>dist</code>目录下的改动，你可以在<code>.gitignore</code>文件下忽略<code>dist</code>目录的改动</p>
<h4 id="将babel的配置写入到-babelrc文件中"><a href="#将babel的配置写入到-babelrc文件中" class="headerlink" title="将babel的配置写入到.babelrc文件中"></a>将<code>babel</code>的配置写入到<code>.babelrc</code>文件中</h4><figure class="highlight css"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="selector-tag">touch</span> <span class="selector-class">.babelrc</span></span><br></pre></td></tr></table></figure>
<p>写入以下内容:</p>
<figure class="highlight json"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">&#123;</span><br><span class="line">  <span class="attr">"presets"</span>: [<span class="string">"es2015"</span>, <span class="string">"stage-2"</span>],</span><br><span class="line">  <span class="attr">"plugins"</span>: []</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<p>这样你就可以去掉 package.json 中的<code>--presets es2015,stage-2</code>参数了</p>
<figure class="highlight 1c"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="string">"scripts"</span>: &#123;</span><br><span class="line">  <span class="string">"start"</span>: <span class="string">"nodemon src/index.js --exec babel-node"</span>,</span><br><span class="line">  <span class="string">"build"</span>: <span class="string">"babel lib -d dist"</span>,</span><br><span class="line">  <span class="string">"serve"</span>: <span class="string">"node dist/index.js"</span></span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<p>文章翻译自 babel 官方提供的 demo，源码下载请点击<a href="https://github.com/babel/example-node-server" target="_blank" rel="noopener">这里</a></p>
<h4 id="续篇"><a href="#续篇" class="headerlink" title="续篇"></a>续篇</h4><ol>
<li><strong>并不是安装了最新版的 nodejs 就能支持<code>import</code></strong><br>比如我现在服务器安装的<code>node</code>版本是最新的<code>v9.3.0</code>，新建一个<code>app.js</code>代码如下：</li>
</ol>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">import</span> moment <span class="keyword">from</span> <span class="string">'moment'</span></span><br><span class="line"></span><br><span class="line"><span class="keyword">async</span> <span class="function"><span class="keyword">function</span> <span class="title">printTime</span>(<span class="params"></span>)</span>&#123;</span><br><span class="line"> <span class="keyword">await</span> <span class="built_in">console</span>.log(moment().format(<span class="string">'YYYY/MM/DD HH:MM:SS'</span>))</span><br><span class="line">&#125;</span><br><span class="line">printTime()</span><br></pre></td></tr></table></figure>
<p>然后使用<code>node app.js</code>运行它，却提示错误：<br><img src="https://file.lantingshucheng.com/blog/node-v.png/default" alt="直接使用node运行"><br>后来去网上查了下虽然 es6 定义了<code>import</code>和<code>export</code>的语法，但是目前<code>nodejs</code>还是不支持。那支持<code>async</code>和<code>await</code>吗？于是我把代码修改了下：</p>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">// import moment from 'moment'</span></span><br><span class="line"></span><br><span class="line"><span class="keyword">async</span> <span class="function"><span class="keyword">function</span> <span class="title">printTime</span>(<span class="params"></span>)</span>&#123;</span><br><span class="line"> <span class="keyword">await</span> <span class="built_in">console</span>.log(<span class="string">'hello world!'</span>)</span><br><span class="line">&#125;</span><br><span class="line">printTime()</span><br></pre></td></tr></table></figure>
<p>这次正常输出了 hello world!，说明<code>async</code>和<code>await</code>是支持的。</p>
<ol start="2">
<li><strong>如果运行 app.js 但是 app.js 引用了其他的文件，在其他的文件中使用了 import 语法，最后编译出来的 js 并不能正常执行</strong><br>解决的方法就是连同引用的文件一起使用 babel 编译了</li>
</ol>
<figure class="highlight routeros"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">babel<span class="built_in"> config </span>-d dist &amp;&amp; babel src -d dist</span><br></pre></td></tr></table></figure>

  </div>
  <div class="statement">
    <hr>  
    1. 如果本文帮到了您，不妨点一下右上角的”<i class="fas fa-share-alt"></i>“按钮。<br>
    2. 除非注明，本博文章均为原创，转载请以链接形式标明本文地址。<br>
    3. 如果你有任何疑问，欢迎发送邮件到我的邮箱<a href="mailto:andyliwr@outlook.com">andyliwr@outlook.com<br>
  </div>
</article>


    <div class="blog-post-comments">
        <div id="gitalk_thread">
            <noscript>加载评论需要在浏览器启用 JavaScript 脚本支持。</noscript>
        </div>
    </div>



        
          <div id="footer-post-container">
  <div id="footer-post">

    <div id="nav-footer" style="display: none">
      <ul>
         
          <li><a href="/">首页</a></li>
         
          <li><a href="/archives/">归档</a></li>
         
          <li><a href="/search/">搜索</a></li>
         
          <li><a href="/tags/">标签</a></li>
         
          <li><a href="/others/">其他文章</a></li>
        
      </ul>
    </div>

    <div id="toc-footer" style="display: none">
      <ol class="toc"><li class="toc-item toc-level-4"><a class="toc-link" href="#前言"><span class="toc-number">1.</span> <span class="toc-text">前言</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#开始"><span class="toc-number">2.</span> <span class="toc-text">开始</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#使用nodemon监听文件变化"><span class="toc-number">3.</span> <span class="toc-text">使用nodemon监听文件变化</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#编译生产环境代码"><span class="toc-number">4.</span> <span class="toc-text">编译生产环境代码</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#将babel的配置写入到-babelrc文件中"><span class="toc-number">5.</span> <span class="toc-text">将babel的配置写入到.babelrc文件中</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#续篇"><span class="toc-number">6.</span> <span class="toc-text">续篇</span></a></li></ol>
    </div>

    <div id="share-footer" style="display: none">
      <ul>
  <li><a class="icon" href="http://www.facebook.com/sharer.php?u=https://andyliwr.github.io/2017/12/05/nodejs_babel/"><i class="fab fa-facebook fa-lg" aria-hidden="true"></i></a></li>
  <li><a class="icon" href="https://twitter.com/share?url=https://andyliwr.github.io/2017/12/05/nodejs_babel/&text=如何使用babel编译nodejs程序"><i class="fab fa-twitter fa-lg" aria-hidden="true"></i></a></li>
  <li><a class="icon" href="http://www.linkedin.com/shareArticle?url=https://andyliwr.github.io/2017/12/05/nodejs_babel/&title=如何使用babel编译nodejs程序"><i class="fab fa-linkedin fa-lg" aria-hidden="true"></i></a></li>
  <li><a class="icon" href="https://pinterest.com/pin/create/bookmarklet/?url=https://andyliwr.github.io/2017/12/05/nodejs_babel/&is_video=false&description=如何使用babel编译nodejs程序"><i class="fab fa-pinterest fa-lg" aria-hidden="true"></i></a></li>
  <li><a class="icon" href="mailto:?subject=如何使用babel编译nodejs程序&body=Check out this article: https://andyliwr.github.io/2017/12/05/nodejs_babel/"><i class="fas fa-envelope fa-lg" aria-hidden="true"></i></a></li>
  <li><a class="icon" href="https://getpocket.com/save?url=https://andyliwr.github.io/2017/12/05/nodejs_babel/&title=如何使用babel编译nodejs程序"><i class="fab fa-get-pocket fa-lg" aria-hidden="true"></i></a></li>
  <li><a class="icon" href="http://reddit.com/submit?url=https://andyliwr.github.io/2017/12/05/nodejs_babel/&title=如何使用babel编译nodejs程序"><i class="fab fa-reddit fa-lg" aria-hidden="true"></i></a></li>
  <li><a class="icon" href="http://www.stumbleupon.com/submit?url=https://andyliwr.github.io/2017/12/05/nodejs_babel/&title=如何使用babel编译nodejs程序"><i class="fab fa-stumbleupon fa-lg" aria-hidden="true"></i></a></li>
  <li><a class="icon" href="http://digg.com/submit?url=https://andyliwr.github.io/2017/12/05/nodejs_babel/&title=如何使用babel编译nodejs程序"><i class="fab fa-digg fa-lg" aria-hidden="true"></i></a></li>
  <li><a class="icon" href="http://www.tumblr.com/share/link?url=https://andyliwr.github.io/2017/12/05/nodejs_babel/&name=如何使用babel编译nodejs程序&description="><i class="fab fa-tumblr fa-lg" aria-hidden="true"></i></a></li>
</ul>

    </div>

    <div id="actions-footer">
        <a id="menu" class="icon" href="#" onclick="$('#nav-footer').toggle();return false;"><i class="fas fa-bars fa-lg" aria-hidden="true"></i> 菜单</a>
        <a id="toc" class="icon" href="#" onclick="$('#toc-footer').toggle();return false;"><i class="fas fa-list fa-lg" aria-hidden="true"></i> 目录</a>
        <a id="share" class="icon" href="#" onclick="$('#share-footer').toggle();return false;"><i class="fas fa-share-alt fa-lg" aria-hidden="true"></i> 分享</a>
        <a id="top" style="display:none" class="icon" href="#" onclick="$('html, body').animate({ scrollTop: 0 }, 'fast');"><i class="fas fa-chevron-up fa-lg" aria-hidden="true"></i> 返回顶部</a>
    </div>

  </div>
</div>

        
        <footer id="footer">
  <div class="footer-left">
    Copyright &copy; 2020 Dikang Li
  </div>
  <div class="footer-right">
    <nav>
      <ul>
         
          <li><a href="/">首页</a></li>
         
          <li><a href="/archives/">归档</a></li>
         
          <li><a href="/search/">搜索</a></li>
         
          <li><a href="/tags/">标签</a></li>
         
          <li><a href="/others/">其他文章</a></li>
        
      </ul>
    </nav>
  </div>
</footer>

    </div>
</body>
</html>
<!-- styles -->
<link rel="stylesheet" href="/lib/font-awesome/css/all.min.css">
<link rel="stylesheet" href="/lib/justified-gallery/css/justifiedGallery.min.css">
<link rel="stylesheet" href="/lib/fancybox/jquery.fancybox.css">

<link rel="stylesheet" href="https://file.lantingshucheng.com/blog/v3/static/styles/gitalk.css">


<!-- jquery -->
<script src="/lib/jquery/jquery.min.js"></script>
<script src="/lib/justified-gallery/js/jquery.justifiedGallery.min.js"></script>
<script src="/lib/fancybox/jquery.fancybox.pack.js"></script>

<script type="text/javascript" src="https://file.lantingshucheng.com/blog/v3/static/scripts/md5.js"></script>
<script type="text/javascript" src="https://file.lantingshucheng.com/blog/v3/static/scripts/gitalk.min.js"></script>

<script src="/js/main.js"></script>
<!-- search -->

<!-- Google Analytics -->

<!-- Baidu Analytics -->

    <script type="text/javascript">
        var _hmt = _hmt || [];
        (function() {
            var hm = document.createElement("script");
            hm.src = "https://hm.baidu.com/hm.js?7851ca7a86be957be994acb77639a5be";
            var s = document.getElementsByTagName("script")[0];
            s.parentNode.insertBefore(hm, s);
        })();
    </script>

<!-- Disqus Comments -->


  <script type="text/javascript">
    window.onload = function(){
      if (window.location.href.indexOf('andyliwr.github.io') > -1) {
        var gitalk = new Gitalk({
          clientID: 'ad6f70df0c70d2b715f9',
          clientSecret: '40384bee244c1e17dd7c37733d21e9ef669e969c',
          repo: 'Andyliwr.github.io',
          owner: 'Andyliwr',
          admin: ['Andyliwr'],
          id: md5(location.pathname),
          distractionFreeMode: 'true'
        })
        gitalk.render('gitalk_thread')
      }
    }
  </script>


